package com.lyy.consolidate;


import java.sql.SQLOutput;

/**
 * @Author:  GZQ
 * @date:  2024/12/2 22:13
 * @description: 巩固练习6
 */

public class HomeWork06 {

    /*
    * (1)在上面类的基础上扩展 新类CheckingAccount
    * 对每次存款和取款都收取1美元的手续费
    *
    * 2)扩展前一个练习的BankAccount类，
    * 新类SavingsAccount每个月都有利息产生
    * (earnMonthlyInterest方法被调用)，并且有每月三次免手续费的存款或取款。
    * 在earnMonthlyInterest 方法中重置交易计数
    *
    * (3)体会重写的好处
    * */

    public static void main(String[] args) {
        CheckingAccount checkingAccount = new CheckingAccount(100);
        // 存款
        checkingAccount.deposit(50); // 150 - 1 = 149
        // 取款
        checkingAccount.withdraw(9); // 149 - 9 = 140 - 1 = 139
        System.out.println("余额为：" + checkingAccount.getBalance());

        // 创建 SavingsAccount
        SavingsAccount savingsAccount = new SavingsAccount(100);
        // 免手续费存款
        savingsAccount.deposit(100);
        savingsAccount.deposit(100);
        savingsAccount.deposit(100);
        System.out.println(savingsAccount.getBalance()); // 400
        savingsAccount.deposit(100);
        System.out.println(savingsAccount.getBalance()); // 500 - 1 = 499

        // 月初, 定时器自动调用一下 earnMonthlyInterest()方法
        savingsAccount.earnMonthlyInterest(); // 统计利息
        System.out.println(savingsAccount.getBalance()); // 499 + 4.99 = 503.99

        savingsAccount.withdraw(100);// 免手续费取款
        System.out.println(savingsAccount.getBalance()); // 503.99 - 100 = 403.99
        savingsAccount.withdraw(100);// 免手续费取款
        savingsAccount.withdraw(100);// 免手续费取款
        System.out.println(savingsAccount.getBalance()); // 403.99 - 200 = 203.99

        savingsAccount.deposit(100); // 口手续费存款
        System.out.println(savingsAccount.getBalance()); // 203.99 + 100 = 303.99 - 1 = 302.99

    }

}
